//drop duplicates in short form
/*use "$temp/census_short_pik_master", clear
keep if qrel == "03" | qrel == "04" | qrel == "05"
tab qrel //how many people just labeled as kids?
duplicates tag pik, gen(dup)
drop if dup
drop dup
save "$temp/census_short_pik_master_clean", replace*/

//drop duplicates in long form; construct parent income/house quintiles
use "$temp/census_long_pik_master", clear

//parent income
gen parent_inc = qinctot_head + qinctot_sp
replace parent_inc = qinctot_head if qage_sp == . //use head income if no spouse

//quartiles, quintiles, deciles, computed within-cohort
forval year = 1983/1994{
	di "`year'"
	xtile parent_inc_quart_`year' = parent_inc[fw = pwt] if birth_yr == `year', nq(4)
	//xtile parent_inc_quint_`year' = parent_inc[fw = pwt] if birth_yr == `year', nq(5)
	xtile parent_inc_dec_`year' = parent_inc[fw = pwt] if birth_yr == `year', nq(10)
}

egen parent_inc_quart = rowmax(parent_inc_quart_*)
//egen parent_inc_quint = rowmax(parent_inc_quint_*)
egen parent_inc_dec = rowmax(parent_inc_dec_*)
//gen parent_inc_med = (parent_inc_quart>2)

drop parent_inc_quart_* parent_inc_dec_* //parent_inc_quint_* 
gen parent_inc_med = (parent_inc_quart>2) //above/below median parent income

//recode housing values
gen house_value = 0
replace house_value = 5000 if svalue == "01"
replace house_value = 12500 if svalue == "02"
replace house_value = 17500 if svalue == "03"
replace house_value = 22500 if svalue == "04"
replace house_value = 27500 if svalue == "05"
replace house_value = 32500 if svalue == "06"
replace house_value = 37500 if svalue == "07"
replace house_value = 45000 if svalue == "08"
replace house_value = 55000 if svalue == "09"
replace house_value = 65000 if svalue == "10"
replace house_value = 75000 if svalue == "11"
replace house_value = 85000 if svalue == "12"
replace house_value = 95000 if svalue == "13"
replace house_value = 112500 if svalue == "14"
replace house_value = 137500 if svalue == "15"
replace house_value = 162500 if svalue == "16"
replace house_value = 187500 if svalue == "17"
replace house_value = 225000 if svalue == "18"
replace house_value = 275000 if svalue == "19"
replace house_value = 350000 if svalue == "20"
replace house_value = 450000 if svalue == "21"
replace house_value = 625000 if svalue == "22"
replace house_value = 875000 if svalue == "23"
replace house_value = 1500000 if svalue == "24"

/*
//quartiles, quintiles, deciles, computed within-cohort
forval year = 1983/1994{
	di "`year'"
	xtile house_med_`year' = house_value[fw = pwt] if birth_yr == `year', nq(2)
	xtile house_quint_`year' = house_value[fw = pwt] if birth_yr == `year', nq(5)
	//xtile house_dec_`year' = house_value[fw = pwt] if birth_yr == `year', nq(10)
}

//house pctiles
egen house_med = rowmax(house_med_*)
egen house_quint = rowmax(house_quint_*)
//egen house_dec = rowmax(house_dec_*)
////gen house_med = (house_quart>2)
drop house_med_* house_quint_* //house_dec_*
*/

//clean up duplicates and relationship values
tab qrel //how many people just labeled as kids? 
keep if qrel == "03" | qrel == "04" | qrel == "05"
duplicates tag pik, gen(dup)
drop if dup
drop dup

//save
save "$temp/census_long_pik_master_clean", replace





//end of dofile
